#!/bin/bash

case $1 in
    dist)
        if [[ $5 == RC* ]]; then
            # RC releases may be hosted at different locations (e.g., downloads.php.net/~edorian/)
            wget https://downloads.php.net/~edorian/php-$2.$3.$4$5.tar.gz \
                -O /opt/src/php-$2.$3.$4$5.tar.gz
            tar -C /opt/src -xf /opt/src/php-$2.$3.$4$5.tar.gz
        else
            # Stable releases are in the distributions folder
            wget https://www.php.net/distributions/php-$2.$3.$4$5.tar.gz \
                -O /opt/src/php-$2.$3.$4$5.tar.gz
            tar -C /opt/src -xf /opt/src/php-$2.$3.$4$5.tar.gz
        fi
        ln -s /opt/src/php-$2.$3.$4$5 /opt/src/php-src
    ;;
    git)
        git clone --branch php-$2.$3.$4$5 --depth 1 https://github.com/php/php-src /opt/src/php-src 1>/dev/null 2>/dev/null
    ;;
esac